<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生详情</title>
</head>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
<body>
    <table align="center" bgcolor="aqua" border="1px" width="80%">
        <tr>
            <th>学&nbsp;&nbsp;号</th>
            <th>姓&nbsp;&nbsp;名</th>
            <th>密&nbsp;&nbsp;码</th>
            <th>年&nbsp;&nbsp;龄</th>
            <th>出生日期</th>
            <th>家庭住址</th>
            <th>
                操&nbsp;&nbsp;作&nbsp;&nbsp;
                <a th:href="@{/student/add}">新增学生</a>&nbsp;&nbsp;
                <a th:href="@{/user/loginOut}">退出登录</a>

            </th>
        </tr>
        <tr th:each="student : ${students}">
            <td  th:text="${student.id}"></td>
            <td  th:text="${student.studentName}"></td>
            <td  th:text="${student.password}"></td>
            <td  th:text="${student.age}"></td>
            <td  th:datetime="${student.birthday}"></td>
            <td  th:text="${student.address}"></td>
            <td>
                <a th:href="'/student/findById?id='+${student.id}+''">修改</a>
                <button th:onclick="'del('+${student.id}+')'">删除</button>
            </td>
        </tr>
    </table>
</body>
<script>
    function del(id){
        $.ajax({
            url:"/student/delete",
            data:JSON.stringify({id:id}),
            type:"post",
            contentType:"application/json",
            success:function(res){
                if (res == "success"){
                    window.location.href=window.location.href
                }
            }
        })
    }
</script>
</html>